#ifndef     OBJMANAGER_H_
# define    OBJMANAGER_H_

# include <algorithm>
# include <utility>
# include <iostream>

template <class C>
class ObjManager
{
public:
    ObjManager(unsigned int const length)
        : _length(length)
    {
        unsigned int i;

        for (i = 0; i < _length; ++i)
            _objs.push_back(node(new C(), false));
    }

    ~ObjManager()
    {
        for (unsigned int i = 0; i < _length; ++i)
            delete _objs[i].first;
    }

    C * getNext()
    {
        for (unsigned int i = 0; i < _length; ++i)
        {
            if (!_objs[i].second)
            {
                _objs[i].second = true;
                return _objs[i].first;
            }
        }
        _objs.push_back(node(new C(), true));
        _length++;
        return _objs.back().first;
    }

    bool disposeOf(C * obj)
    {
        objIt it = find(_objs.begin(), _objs.end(), node(obj, true));

        if (it != _objs.end())
        {
            (*it).second = false;
            return true;
        }
        return false;
    }

private:
    typedef typename std::pair<C*, bool> node;
    typedef typename std::vector<std::pair<C*, bool> >::iterator objIt;

private:
    unsigned int        _length;
    std::vector<node>   _objs;
};

#endif   /* OBJMANAGER_H_ */
